// 新增页面form表单编辑钱事件

import beforeEditForm from '../request/beforeEditForm';

const cacheData = {};

export default async function(props, moduleId, fieldName, value, item) {
    const {
        form: {
            getAllFormValue,
            setFormItemsDisabled
        },
        humanResourceOrganizationValue: {
            refpk
        },
        meta: {
            getMeta,
            setMeta
        }
    } = this.props;

    let template = getMeta();
    
    let postData = {
        areaCode: moduleId,
        func_type: '1',
        key: fieldName,
        model: getAllFormValue(moduleId),
        pk_org: refpk
    };

    try {
        let res = await beforeEditForm(postData);
        let editable = res.data.editable;

        template[moduleId].items.map((item, index) => {
            if(item.attrcode === fieldName) {
                res.data.refParam && Object.assign(item['queryCondition'], res.data.refParam);
                item.disabled = !editable
            }
        });

        setFormItemsDisabled(moduleId, {
            [fieldName]: !editable
        });
        setMeta(template);
        return true;
    }
    catch(e) {
    }
}
